package com.example.mvp.mvppromote.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.mvp.mvppromote.R;
import com.example.mvp.mvppromote.base.BaseFragment;
import com.example.mvp.mvppromote.presenter.CustomPresenter;
import com.example.mvp.mvppromote.ui.activity.LineViewActivity;
import com.example.mvp.mvppromote.ui.iview.ICustomView;

import java.util.List;

import butterknife.BindView;

/**
 * Created by wutongyu on 16/7/8.
 */
public class CustomViewFragment extends BaseFragment<CustomPresenter> implements ICustomView {

    @BindView(R.id.layout)
    LinearLayout layout;

    @Override
    protected CustomPresenter getPresenter() {
        return new CustomPresenter(getContext(), this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_customview;
    }

    @Override
    protected void initData() {
        getPresenter().getData();
    }

    @Override
    public void updateViewList(final List<String> list) {
        for (final String str:list){
            TextView textView=new TextView(getContext());
            textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            textView.setTextSize(16);
            textView.setTextColor(getResources().getColor(R.color.text_shen));
            textView.setText(str);
            textView.setPadding(15,15,15,15);
            textView.setGravity(Gravity.CENTER);
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (str.equals(list.get(0))){
                        startActivity(new Intent(getActivity(), LineViewActivity.class));
                    }
                }
            });
            layout.addView(textView);
        }

    }

    @Override
    public Context getMyContext() {
        return getContext();
    }
}
